<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Prepend bucket to brigade</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.stream-bucket-prepend" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">stream_bucket_prepend</h1>
  <p class="verinfo">(PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">stream_bucket_prepend</span> &mdash; <span class="dc-title">
   Prepend bucket to brigade
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.stream-bucket-prepend-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>stream_bucket_prepend</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$brigade</code></span>
   , <span class="methodparam"><span class="type">object</span> <code class="parameter">$bucket</code></span>
   ) : <span class="type"><span class="type void">void</span></span></div>

  <p class="para rdfs-comment">
    This function can be called to prepend a bucket to a bucket brigade. It
    is typically called from <span class="methodname"><a href="php_user_filter.filter.html" class="methodname">php_user_filter::filter()</a></span>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.stream-bucket-prepend-parameters">
  <h3 class="title">参数</h3>
  <dl>

   
    <dt>
<code class="parameter">brigade</code></dt>

    <dd>

     <p class="para">
      <code class="parameter">brigade</code> is a resource pointing to a <em>bucket brigade</em>
      which contains one or more <em>bucket</em> objects.
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">bucket</code></dt>

    <dd>

     <p class="para">
      A bucket object.
     </p>
    </dd>

   
  </dl>

 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.stream-bucket-prepend-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   没有返回值。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.stream-bucket-prepend-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4812">
    <p><strong>Example #1 <span class="function"><strong>stream_bucket_prepend()</strong></span> examples</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">foo&nbsp;</span><span style="color: #007700">extends&nbsp;</span><span style="color: #0000BB">php_user_filter&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;protected&nbsp;</span><span style="color: #0000BB">$calls&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">;<br />&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">filter</span><span style="color: #007700">(</span><span style="color: #0000BB">$in</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$out</span><span style="color: #007700">,&nbsp;&amp;</span><span style="color: #0000BB">$consumed</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$closing</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;(</span><span style="color: #0000BB">$bucket&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">stream_bucket_make_writeable</span><span style="color: #007700">(</span><span style="color: #0000BB">$in</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$consumed&nbsp;</span><span style="color: #007700">+=&nbsp;</span><span style="color: #0000BB">$bucket</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">datalen</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">calls</span><span style="color: #007700">++&nbsp;==&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;This&nbsp;bucket&nbsp;will&nbsp;appear&nbsp;again&nbsp;before&nbsp;any&nbsp;other&nbsp;bucket.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">stream_bucket_prepend</span><span style="color: #007700">(</span><span style="color: #0000BB">$in</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$bucket</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">PSFS_FEED_ME</span><span style="color: #007700">;<br />&nbsp;&nbsp;}<br />}<br /></span><span style="color: #0000BB">stream_filter_register</span><span style="color: #007700">(</span><span style="color: #DD0000">'test'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'foo'</span><span style="color: #007700">);<br />print&nbsp;&nbsp;</span><span style="color: #0000BB">file_get_contents</span><span style="color: #007700">(</span><span style="color: #DD0000">'php://filter/read=test/resource=foo'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>

</div></div></div></body></html>